home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Applications / Alpha.5.96 folder / Tcl / SystemCode / diff.tcl < prev    next >
Encoding:
Text File  |  1994-09-20  |  4.4 KB  |  177 lines  |  [TEXT/ALFA]

  1. # Usage: diff [-#] [-abBcdefhHilnNprstTuvw] [-C lines] [-F regexp] [-I regexp]
  2. #        [-L label [-L label]] [-S file] [-D symbol] [+ignore-blank-lines]
  3. #        [+context[=lines]] [+unified[=lines]] [+ifdef=symbol]
  4. #        [+show-function-line=regexp]
  5. #        [+speed-large-files] [+ignore-matching-lines=regexp] [+new-file]
  6. #        [+initial-tab] [+starting-file=file] [+text] [+all-text] [+ascii]
  7. #        [+minimal] [+ignore-space-change] [+ed] [+reversed-ed] [+ignore-case]
  8. #        [+print] [+rcs] [+show-c-function] [+binary] [+brief] [+recursive]
  9. #        [+report-identical-files] [+expand-tabs] [+ignore-all-space]
  10. #        [+file-label=label [+file-label=label]] [+version] path1 path2
  11.  
  12.  
  13. proc compareDirectories {} {
  14.     alertnote "Not yet"
  15.     return
  16.  
  17.     set dir1 [string trimright [get_directory] {:}]
  18.     set dir2 [string trimright [get_directory] {:}]
  19.  
  20.     set glob1 [glob -t TEXT "$dir1:*"]
  21.     set glob2 [glob -t TEXT "$dir2:*"]
  22.  
  23.     new -n {* Directory Comparison *}
  24.     insertText "Dir1 : \"$dir1\"\rDir2: \"$dir2\"\r"
  25.     foreach f $glob1 {
  26.         set tail [file tail $f]
  27.         if {[lsearch $glob2 "*:$tail"] >= 0} {
  28.             insertText "In both directories: $tail\r"
  29.             message "Diffing '$tail'"
  30.             insertText [xdiff "$dir1:$tail" "$dir2:$tail"] "\r"
  31.         } else {
  32.             insertText "Only in first: $tail\r"
  33.         }
  34.     }
  35.     foreach f $glob2 {
  36.         set tail [file tail $f]
  37.         if {[lsearch $glob1 "*:$tail"] < 0} {
  38.             insertText "Only in second: $tail\r"
  39.         }
  40.     }
  41. }
  42.  
  43.  
  44. proc compareFiles {} {
  45.     global tileWidth tileHeight tileTop tileLeft
  46.     global diffOne diffTwo
  47.  
  48.     set diffOne [getfile "Select your first file:"]
  49.     set diffTwo [getfile "Select your second file:"]
  50.     
  51.     if {[lsearch [winNames -f] $diffOne] >= 0} {
  52.         bringToFront $diffOne
  53.         killWindow
  54.         if {[lsearch [winNames -f] $diffOne] >= 0} {return}
  55.     }
  56.     if {[lsearch [winNames -f] $diffTwo] >= 0} {
  57.         bringToFront $diffTwo
  58.         killWindow
  59.         if {[lsearch [winNames -f] $diffTwo] >= 0} {return}
  60.     }
  61.     
  62.     set numWins 2
  63.     set margin 4
  64.     set width [expr ($tileWidth/$numWins)-$margin]
  65.     set height [expr $tileHeight - 200]
  66.     set hor $tileLeft
  67.  
  68.     edit -g $hor $tileTop $width $height $diffOne
  69.     set diffOne [lindex [winNames -f] 0]
  70.     incr hor [expr $width + $margin]
  71.     edit -g $hor $tileTop $width $height $diffTwo
  72.     set diffTwo [lindex [winNames -f] 0]
  73.     
  74.     doTheCompare
  75. }
  76.  
  77.  
  78. proc compareWindows {} {
  79.     global tileWidth tileHeight tileTop tileLeft
  80.     global diffOne diffTwo
  81.  
  82.     set wins [winNames -f] 
  83.     if {[llength $wins] < 2} {
  84.         message "Need two windows"
  85.         return
  86.     }
  87.     set diffOne [lindex $wins 0]
  88.     set diffTwo [lindex $wins 1]
  89.     
  90.     set numWins 2
  91.     set margin 4
  92.     set width [expr ($tileWidth/$numWins)-$margin]
  93.     set width [expr {$width + $margin / $numWins}]
  94.     set height [expr $tileHeight - 200]
  95.     set hor $tileLeft
  96.  
  97.     for {set i 0} {$i < $numWins} {incr i} {
  98.         moveWin [lindex $wins $i] 1000 0
  99.         sizeWin [lindex $wins $i] $width $height
  100.     }
  101.  
  102.     for {set i 0} {$i < $numWins} {incr i} {
  103.         moveWin [lindex $wins $i] $hor $tileTop
  104.         set hor [expr $hor+$width+$margin]
  105.     }
  106.     
  107.     doTheCompare
  108. }
  109.  
  110.  
  111. proc trimnum {str} {
  112.     if {[regexp -indices { <[0-9]+>} $str ind]} {
  113.         return [string range $str 0 [expr [lindex $ind 0] - 1]]
  114.     } else {
  115.         return $str
  116.     }
  117. }
  118.  
  119.  
  120. proc doTheCompare {} {
  121.     global tileLeft tileTop tileWidth tileHeight diffFlags
  122.     global diffOne diffTwo winModes HOME
  123.     
  124.     launch "$HOME:Tools:GNU Diff"
  125.     set dtext [dosc -n "GNU Diff" -s "$diffFlags \"[trimnum $diffOne]\" \"[trimnum $diffTwo]\""]
  126.  
  127.     set top [expr $tileTop + $tileHeight - 178]
  128.     new -n {* File Comparison *} -g $tileLeft $top [expr $tileWidth - 6] 178
  129.     changeMode [set winModes([lindex [winNames] 0]) Diff]
  130.     insertText "\r$dtext\r"
  131.     goto 0
  132.     setWinInfo dirty 0
  133.     select 1 [nextLineStart 1]
  134. }
  135.  
  136.  
  137. proc upDiff {} {
  138.     set limit 0
  139.     set res [search -f 0 -r 1 {^[^-<>]} [expr [getPos] - 1]]
  140.     set pos [lindex $res 0]
  141.     select $pos [nextLineStart $pos]
  142.     
  143. }
  144.  
  145. proc downDiff {} {
  146.     set limit 0
  147.     set res [search -f 1 -r 1 {^[^-<>]} [expr [getPos] + 1]]
  148.     set pos [lindex $res 0]
  149.     select $pos [nextLineStart $pos]
  150.     
  151. }
  152.  
  153. #           n1 a n3,n4
  154. #           n1,n2 d n3
  155. #           n1,n2 c n3,n4
  156. proc selectDiff {} {
  157.     global diffOne diffTwo
  158.     
  159.     set text [getText [lineStart [getPos]] [expr [nextLineStart [getPos]] - 1]]
  160.     
  161.     if {![regexp {[acd]} $text char]} return
  162.     set res [split $text $char]
  163.     if {![scan [lindex $res 0] "%d" one]} return
  164.     if {![scan [lindex $res 1] "%d" two]} return
  165.  
  166.     display -w $diffOne [rowColToPos -w $diffOne $one 0]
  167.     display -w $diffTwo [rowColToPos -w $diffTwo $two 0]
  168. }
  169.  
  170.  
  171. bind '\r'        selectDiff    Diff
  172. bind enter        selectDiff    Diff
  173. bind down         downDiff Diff
  174. bind up         upDiff Diff
  175.  
  176.  
  177.